package com.qinggeng.project.system.controller;

import com.qinggeng.common.utils.poi.ExcelUtil;
import com.qinggeng.framework.aspectj.lang.annotation.Log;
import com.qinggeng.framework.aspectj.lang.enums.BusinessType;
import com.qinggeng.framework.web.controller.BaseController;
import com.qinggeng.framework.web.domain.AjaxResult;
import com.qinggeng.framework.web.page.TableDataInfo;
import com.qinggeng.project.system.domain.OrderStatistics;
import com.qinggeng.project.system.service.IOrderStatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;
/**
 * 订单数据统计Controller
 *
 * @author qinggeng
 * @date 2020-06-30
 */
@RestController
@RequestMapping("/system/orderStatistics")
public class OrderStatisticsController extends BaseController
{
    @Autowired
    private IOrderStatisticsService orderStatisticsService;

    /**
     * 查询订单数据统计列表
     */
    @PreAuthorize("@ss.hasPermi('system:orderStatistics:list')")
    @GetMapping("/list")
    public TableDataInfo list(OrderStatistics orderStatistics)
    {
        startPage();
        List<OrderStatistics> list = orderStatisticsService.selectOrderStatisticsList(orderStatistics);
        return getDataTable(list);
    }

    /**
     * 导出订单数据统计列表
     */
    @PreAuthorize("@ss.hasPermi('system:orderStatistics:export')")
    @Log(title = "订单数据统计", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(OrderStatistics orderStatistics)
    {
        List<OrderStatistics> list = orderStatisticsService.selectOrderStatisticsList(orderStatistics);
        ExcelUtil<OrderStatistics> util = new ExcelUtil<OrderStatistics>(OrderStatistics.class);
        return util.exportExcel(list, "orderStatistics");
    }

    /**
     * 获取订单数据统计详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:orderStatistics:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(orderStatisticsService.selectOrderStatisticsById(id));
    }

    /**
     * 新增订单数据统计
     */
    @PreAuthorize("@ss.hasPermi('system:orderStatistics:add')")
    @Log(title = "订单数据统计", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrderStatistics orderStatistics)
    {
        return toAjax(orderStatisticsService.insertOrderStatistics(orderStatistics));
    }

    /**
     * 修改订单数据统计
     */
    @PreAuthorize("@ss.hasPermi('system:orderStatistics:edit')")
    @Log(title = "订单数据统计", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrderStatistics orderStatistics)
    {
        return toAjax(orderStatisticsService.updateOrderStatistics(orderStatistics));
    }

    /**
     * 删除订单数据统计
     */
    @PreAuthorize("@ss.hasPermi('system:orderStatistics:remove')")
    @Log(title = "订单数据统计", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(orderStatisticsService.deleteOrderStatisticsByIds(ids));
    }


    /**
     * 查询订单数据统计列表
     */
   // @PreAuthorize("@ss.hasPermi('system:orderStatistics:point')")
    @GetMapping("/point")
    public TableDataInfo orderStatisticsList(Long startTime,Long endTime)
    {
        startPage();
        List<OrderStatistics> orderStatisticsList=orderStatisticsService.selectPointOrderStatisticsList(startTime,endTime);

        return getDataTable(orderStatisticsList);
    }
}
